import org.apache.spark.sql.SparkSession
object intersection{
  def main(args: Array[String]):Unit ={
    val spark=SparkSession.builder
      .appName(name= "LocaLHodeDemo")
      .master(master="local[*]")
      //本地模式,使用所有核心
      .getOrCreate()
    //获取 SparkContext
    val sc =spark.sparkContext
    try {
      val c_rdd1 = sc.parallelize(List(('a',1),('a',1),('b',2),('c',1)))
      val c_rdd2 = sc.parallelize(List(('a',1),('b',1),('d',1)))
      c_rdd1.intersection(c_rdd2).collect
      val result = c_rdd1.intersection(c_rdd2).collect()
      println(s"共同元素为：${result.mkString(", ")}")
    }
    finally {
      spark.stop()
    }
  }
}